package com.linxiao.hrcrm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.linxiao.hrcrm.vo.ArticleContentVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.linxiao.hrcrm.domain.ArticleContent;
import com.linxiao.hrcrm.service.IArticleContentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 内容Controller
 *
 * @author ruoyi
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/article/content")
public class ArticleContentController extends BaseController {
    @Autowired
    private IArticleContentService articleContentService;

    /**
     * 查询内容列表
     */
    @PreAuthorize("@ss.hasPermi('article:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleContent articleContent) {
        startPage();
        List<ArticleContent> list = articleContentService.selectArticleContentList(articleContent);
        return getDataTable(list);
    }

    /**
     * 前端使用接口
     * @param articleContentVO
     * @return
     */
    @GetMapping("/page")
    public TableDataInfo page(ArticleContentVO articleContentVO) {
        startPage();
        List<ArticleContentVO> list = articleContentService.selectArticleContentPage(articleContentVO);
        return getDataTable(list);
    }

    /**
     * 前端使用接口 - 获取所有的标签
     * @param mchId
     * @return
     */
    @GetMapping("/all_tags")
    public TableDataInfo allTags(@RequestParam String mchId) {
        startPage();
        List<String> list = articleContentService.selectAllTags(mchId);
        return getDataTable(list);
    }

    /**
     * 导出内容列表
     */
    @PreAuthorize("@ss.hasPermi('article:content:export')")
    @Log(title = "内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleContent articleContent) {
        List<ArticleContent> list = articleContentService.selectArticleContentList(articleContent);
        ExcelUtil<ArticleContent> util = new ExcelUtil<ArticleContent>(ArticleContent.class);
        util.exportExcel(response, list, "内容数据");
    }

    /**
     * 获取内容详细信息
     */
    @GetMapping(value = "loadById/{id}")
    public AjaxResult loadById(@PathVariable("id") Long id) {
        return success(articleContentService.selectArticleContentById(id));
    }

    /**
     * 获取内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:content:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(articleContentService.selectArticleContentById(id));
    }

    /**
     * 新增内容
     */
    @PreAuthorize("@ss.hasPermi('article:content:add')")
    @Log(title = "内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleContent articleContent) {
        return toAjax(articleContentService.insertArticleContent(articleContent));
    }

    /**
     * 修改内容
     */
    @PreAuthorize("@ss.hasPermi('article:content:edit')")
    @Log(title = "内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleContent articleContent) {
        return toAjax(articleContentService.updateArticleContent(articleContent));
    }

    /**
     * 删除内容
     */
    @PreAuthorize("@ss.hasPermi('article:content:remove')")
    @Log(title = "内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(articleContentService.deleteArticleContentByIds(ids));
    }
}
